home *** CD-ROM | disk | FTP | other *** search
/ SGI Developer Toolbox 6.1 / SGI Developer Toolbox 6.1 - Disc 4.iso / public / GNU / emacs.inst / emacs19.idb / usr / gnu / info / elisp-15.z / elisp-15
Encoding:
GNU Info File  |  1994-08-02  |  47.8 KB  |  1,180 lines

  1. This is Info file elisp, produced by Makeinfo-1.55 from the input file
  2. elisp.texi.
  3.  
  4.    This version is newer than the second printed edition of the GNU
  5. Emacs Lisp Reference Manual.  It corresponds to Emacs Version 19.19.
  6.  
  7.    Published by the Free Software Foundation 675 Massachusetts Avenue
  8. Cambridge, MA 02139 USA
  9.  
  10.    Copyright (C) 1990, 1991, 1992, 1993 Free Software Foundation, Inc.
  11.  
  12.    Permission is granted to make and distribute verbatim copies of this
  13. manual provided the copyright notice and this permission notice are
  14. preserved on all copies.
  15.  
  16.    Permission is granted to copy and distribute modified versions of
  17. this manual under the conditions for verbatim copying, provided that
  18. the entire resulting derived work is distributed under the terms of a
  19. permission notice identical to this one.
  20.  
  21.    Permission is granted to copy and distribute translations of this
  22. manual into another language, under the above conditions for modified
  23. versions, except that this permission notice may be stated in a
  24. translation approved by the Foundation.
  25.  
  26.    Permission is granted to copy and distribute modified versions of
  27. this manual under the conditions for verbatim copying, provided also
  28. that the section entitled "GNU Emacs General Public License" is included
  29. exactly as in the original, and provided that the entire resulting
  30. derived work is distributed under the terms of a permission notice
  31. identical to this one.
  32.  
  33.    Permission is granted to copy and distribute translations of this
  34. manual into another language, under the above conditions for modified
  35. versions, except that the section entitled "GNU Emacs General Public
  36. License" may be included in a translation approved by the Free Software
  37. Foundation instead of in the original English.
  38.  
  39. 
  40. File: elisp,  Node: Keymap Terminology,  Next: Format of Keymaps,  Up: Keymaps
  41.  
  42. Keymap Terminology
  43. ==================
  44.  
  45.    A "keymap" is a table mapping event types to definitions (which can
  46. be any Lisp objects, though only certain types are meaningful for
  47. execution by the command loop).  Given an event (or an event type) and a
  48. keymap, Emacs can get the event's definition.  Events include ordinary
  49. ASCII characters, function keys, and mouse actions (*note Input
  50. Events::.).
  51.  
  52.    A sequence of input events that form a unit is called a "key
  53. sequence", or "key" for short.  A sequence of one event is always a key
  54. sequence, and so are some multi-event sequences.
  55.  
  56.    A keymap determines a binding or definition for any key sequence.  If
  57. the key sequence is a single event, its binding is the definition of the
  58. event in the keymap.  The binding of a key sequence of more than one
  59. event is found by an iterative process: the binding of the first event
  60. is found, and must be a keymap; then the second event's binding is found
  61. in that keymap, and so on until all the events in the key sequence are
  62. used up.
  63.  
  64.    If the binding of a key sequence is a keymap, we call the key
  65. sequence a "prefix key".  Otherwise, we call it a "complete key"
  66. (because no more characters can be added to it).  If the binding is
  67. `nil', we call the key "undefined".  Examples of prefix keys are `C-c',
  68. `C-x', and `C-x 4'.  Examples of defined complete keys are `X', RET,
  69. and `C-x 4 C-f'.  Examples of undefined complete keys are `C-x C-g',
  70. and `C-c 3'.  *Note Prefix Keys::, for more details.
  71.  
  72.    The rule for finding the binding of a key sequence assumes that the
  73. intermediate bindings (found for the events before the last) are all
  74. keymaps; if this is not so, the sequence of events does not form a
  75. unit--it is not really a key sequence.  In other words, removing one or
  76. more events from the end of any valid key must always yield a prefix
  77. key.  For example, `C-f C-f' is not a key; `C-f' is not a prefix key,
  78. so a longer sequence starting with `C-f' cannot be a key.
  79.  
  80.    Note that the set of possible multi-event key sequences depends on
  81. the bindings for prefix keys; therefore, it can be different for
  82. different keymaps, and can change when bindings are changed.  However,
  83. a one-event sequence is always a key sequence, because it does not
  84. depend on any prefix keys for its well-formedness.
  85.  
  86.    At any time, several primary keymaps are "active"--that is, in use
  87. for finding key bindings.  These are the "global map", which is shared
  88. by all buffers; the "local keymap", which is usually associated with a
  89. specific major mode; and zero or more "minor mode keymaps" which belong
  90. to currently enabled minor modes.  (Not all minor modes have keymaps.)
  91. The local keymap bindings shadow (i.e., take precedence over) the
  92. corresponding global bindings.  The minor mode keymaps shadow both
  93. local and global keymaps.  *Note Active Keymaps::, for details.
  94.  
  95. 
  96. File: elisp,  Node: Format of Keymaps,  Next: Creating Keymaps,  Prev: Keymap Terminology,  Up: Keymaps
  97.  
  98. Format of Keymaps
  99. =================
  100.  
  101.    A keymap is a list whose CAR is the symbol `keymap'.  The remaining
  102. elements of the list define the key bindings of the keymap.  Use the
  103. function `keymapp' (see below) to test whether an object is a keymap.
  104.  
  105.    An ordinary element is a cons cell of the form `(TYPE .  BINDING)'.
  106. This specifies one binding which applies to events of type TYPE.  Each
  107. ordinary binding applies to events of a particular "event type", which
  108. is always a character or a symbol.  *Note Classifying Events::.
  109.  
  110.    A cons cell whose CAR is `t' is a "default key binding"; any event
  111. not bound by other elements of the keymap is given BINDING as its
  112. binding.  Default bindings allow a keymap to bind all possible event
  113. types without having to enumerate all of them.  A keymap that has a
  114. default binding completely masks any lower-precedence keymap.
  115.  
  116.    If an element of a keymap is a vector, the vector counts as bindings
  117. for all the ASCII characters; vector element N is the binding for the
  118. character with code N.  This is a more compact way to record lots of
  119. bindings.  A keymap with such a vector is called a "full keymap".
  120. Other keymaps are called "sparse keymaps".
  121.  
  122.    When a keymap contains a vector, it always defines a binding for
  123. every ASCII character even if the vector element is `nil'.  Such a
  124. binding of `nil' overrides any default binding in the keymap.  However,
  125. default bindings are still meaningful for events that are not ASCII
  126. characters.  A binding of `nil' does *not* override lower-precedence
  127. keymaps; thus, if the local map gives a binding of `nil', Emacs uses
  128. the binding from the global map.
  129.  
  130.    Aside from bindings, a keymap can also have a string as an element.
  131. This is called the "overall prompt string" and makes it possible to use
  132. the keymap as a menu.  *Note Menu Keymaps::.
  133.  
  134.    Keymaps do not directly record bindings for the meta characters,
  135. whose codes are from 128 to 255.  Instead, meta characters are regarded
  136. for purposes of key lookup as sequences of two characters, the first of
  137. which is ESC (or whatever is currently the value of
  138. `meta-prefix-char').  Thus, the key `M-a' is really represented as `ESC
  139. a', and its global binding is found at the slot for `a' in `esc-map'.
  140.  
  141.    Here as an example is the local keymap for Lisp mode, a sparse
  142. keymap.  It defines bindings for DEL and TAB, plus `C-c C-l', `M-C-q',
  143. and `M-C-x'.
  144.  
  145.      lisp-mode-map
  146.      =>
  147.      (keymap
  148.       ;; TAB
  149.       (9 . lisp-indent-line)
  150.       ;; DEL
  151.       (127 . backward-delete-char-untabify)
  152.       (3 keymap
  153.          ;; `C-c C-l'
  154.          (12 . run-lisp))
  155.       (27 keymap
  156.           ;; `M-C-q', treated as `ESC C-q'
  157.           (17 . indent-sexp)
  158.           ;; `M-C-x', treated as `ESC C-x'
  159.           (24 . lisp-send-defun)))
  160.  
  161.  - Function: keymapp OBJECT
  162.      This function returns `t' if OBJECT is a keymap, `nil' otherwise.
  163.      Practically speaking, this function tests for a list whose CAR is
  164.      `keymap'.
  165.  
  166.           (keymapp '(keymap))
  167.               => t
  168.           (keymapp (current-global-map))
  169.               => t
  170.  
  171. 
  172. File: elisp,  Node: Creating Keymaps,  Next: Inheritance and Keymaps,  Prev: Format of Keymaps,  Up: Keymaps
  173.  
  174. Creating Keymaps
  175. ================
  176.  
  177.    Here we describe the functions for creating keymaps.
  178.  
  179.  - Function: make-keymap &optional PROMPT
  180.      This function creates and returns a new full keymap (i.e., one
  181.      which contains a vector of length 128 for defining all the ASCII
  182.      characters).  The new keymap initially binds all ASCII characters
  183.      to `nil', and does not bind any other kind of event.
  184.  
  185.           (make-keymap)
  186.               => (keymap [nil nil nil ... nil nil])
  187.  
  188.      If you specify PROMPT, that becomes the overall prompt string for
  189.      the keymap.  The prompt string is useful for menu keymaps (*note
  190.      Menu Keymaps::.).
  191.  
  192.  - Function: make-sparse-keymap &optional PROMPT
  193.      This function creates and returns a new sparse keymap with no
  194.      entries.  The new keymap does not bind any events.  The argument
  195.      PROMPT specifies a prompt string, as in `make-keymap'.
  196.  
  197.           (make-sparse-keymap)
  198.               => (keymap)
  199.  
  200.  - Function: copy-keymap KEYMAP
  201.      This function returns a copy of KEYMAP.  Any keymaps which appear
  202.      directly as bindings in KEYMAP are also copied recursively, and so
  203.      on to any number of levels.  However, recursive copying does not
  204.      take place when the definition of a character is a symbol whose
  205.      function definition is a keymap; the same symbol appears in the
  206.      new copy.
  207.  
  208.           (setq map (copy-keymap (current-local-map)))
  209.           => (keymap
  210.                ;; (This implements meta characters.)
  211.                (27 keymap
  212.                    (83 . center-paragraph)
  213.                    (115 . center-line))
  214.                (9 . tab-to-tab-stop))
  215.           
  216.           (eq map (current-local-map))
  217.               => nil
  218.           (equal map (current-local-map))
  219.               => t
  220.  
  221. 
  222. File: elisp,  Node: Inheritance and Keymaps,  Next: Prefix Keys,  Prev: Creating Keymaps,  Up: Keymaps
  223.  
  224. Inheritance and Keymaps
  225. =======================
  226.  
  227.    A keymap can inherit the bindings of another keymap.  Do do this,
  228. make a keymap whose "tail" is another existing keymap to inherit from.
  229. Such a keymap looks like this:
  230.  
  231.      (keymap BINDINGS... . OTHER-KEYMAP)
  232.  
  233. The effect is that this keymap inherits all the bindings of
  234. OTHER-KEYMAP, whatever they may be at the time a key is looked up, but
  235. can add to them or override them with BINDINGS.
  236.  
  237.    If you change the bindings in OTHER-KEYMAP using `define-key' or
  238. other key-binding functions, these changes are visible in the
  239. inheriting keymap unless shadowed by BINDINGS.  The converse is not
  240. true: if you use `define-key' to change the inheriting keymap, that
  241. affects BINDINGS, but has no effect on OTHER-KEYMAP.
  242.  
  243.    Here is an example showing how to make a keymap that inherits from
  244. `text-mode-map':
  245.  
  246.      (setq my-mode-map (cons 'keymap text-mode-map))
  247.  
  248. 
  249. File: elisp,  Node: Prefix Keys,  Next: Menu Keymaps,  Prev: Inheritance and Keymaps,  Up: Keymaps
  250.  
  251. Prefix Keys
  252. ===========
  253.  
  254.    A "prefix key" has an associated keymap which defines what to do
  255. with key sequences that start with the prefix key.  For example, `C-x'
  256. is a prefix key, and it uses a keymap which is also stored in the
  257. variable `ctl-x-map'.  Here is a list of the standard prefix keys of
  258. Emacs and their keymaps:
  259.  
  260.    * `esc-map' is used for events that follow ESC.  Thus, the global
  261.      definitions of all meta characters are actually found here.  This
  262.      map is also the function definition of `ESC-prefix'.
  263.  
  264.    * `help-map' is used for events that follow `C-h'.
  265.  
  266.    * `mode-specific-map' is for events that follow `C-c'.  This map is
  267.      not actually mode specific; its name was chosen to be informative
  268.      for the user in `C-h b' (`display-bindings'), where it describes
  269.      the main use of the `C-c' prefix key.
  270.  
  271.    * `ctl-x-map' is the variable name for the map used for events that
  272.      follow `C-x'.  This map is also the function definition of
  273.      `Control-X-prefix'.
  274.  
  275.    * `ctl-x-4-map' is used for events that follow `C-x 4'.
  276.  
  277.    * `ctl-x-5-map' used is for events that follow `C-x 5'.
  278.  
  279.    * A nameless keymap is used for events that follow `C-x n'.  Others
  280.      are used for events following `C-x r' and `C-x a'.
  281.  
  282.    The binding of a prefix key is the keymap to use for looking up the
  283. events that follow the prefix key.  (It may instead be a symbol whose
  284. function definition is a keymap.  The effect is the same, but the symbol
  285. serves as a name for the prefix key.)  Thus, the binding of `C-x' is
  286. the symbol `Control-X-prefix', whose function definition is the keymap
  287. for `C-x' commands.  (The same keymap is also the value of `ctl-x-map'.)
  288.  
  289.    Prefix key definitions of this sort can appear in any active keymap.
  290. The definitions of `C-c', `C-x', `C-h' and ESC as prefix keys appear in
  291. the global map, so these prefix keys are always available.  Major and
  292. minor modes can redefine a key as a prefix by putting a prefix key
  293. definition for it in the local map or the minor mode's map.  *Note
  294. Active Keymaps::.
  295.  
  296.    If a key is defined as a prefix in more than one active map, then the
  297. various definitions are in effect merged: the commands defined in the
  298. minor mode keymaps come first, followed by those in the local map's
  299. prefix definition, and then by those from the global map.
  300.  
  301.    In the following example, we make `C-p' a prefix key in the local
  302. keymap, in such a way that `C-p' is identical to `C-x'.  Then the
  303. binding for `C-p C-f' is the function `find-file', just like `C-x C-f'.
  304. The key sequence `C-p 6' is not found in any active keymap.
  305.  
  306.      (use-local-map (make-sparse-keymap))
  307.          => nil
  308.      (local-set-key "\C-p" ctl-x-map)
  309.          => nil
  310.      (key-binding "\C-p\C-f")
  311.          => find-file
  312.      
  313.      (key-binding "\C-p6")
  314.          => nil
  315.  
  316.  - Function: define-prefix-command SYMBOL
  317.      This function defines SYMBOL as a prefix command: it creates a
  318.      full keymap and stores it as SYMBOL's function definition.
  319.      Storing the symbol as the binding of a key makes the key a prefix
  320.      key which has a name.  It also sets SYMBOL as a variable, to have
  321.      the keymap as its value.  The function returns SYMBOL.
  322.  
  323.      In Emacs version 18, only the function definition of SYMBOL was
  324.      set, not the value as a variable.
  325.  
  326. 
  327. File: elisp,  Node: Menu Keymaps,  Next: Active Keymaps,  Prev: Prefix Keys,  Up: Keymaps
  328.  
  329. Menu Keymaps
  330. ============
  331.  
  332.    A keymap can define a menu as well as ordinary keys and mouse button
  333. meanings.  Menus are normally actuated with the mouse, but they can work
  334. with the keyboard also.
  335.  
  336. * Menu:
  337.  
  338. * Defining Menus::        How to make a keymap that defines a menu.
  339. * Mouse Menus::            How users actuate the menu with the mouse.
  340. * Keyboard Menus::        How they actuate it with the keyboard.
  341. * Menu Example::        Making a simple menu.
  342. * Menu Bar::            How to customize the menu bar.
  343. * Modifying Menus::             How to add new items to a menu.
  344.  
  345. 
  346. File: elisp,  Node: Defining Menus,  Next: Mouse Menus,  Up: Menu Keymaps
  347.  
  348. Defining Menus
  349. --------------
  350.  
  351.    A keymap is suitable for menu use if it has an "overall prompt
  352. string", which is a string that appears as an element of the keymap.
  353. (*Note Format of Keymaps::.)  The string should describe the purpose of
  354. the menu.  The easiest way to construct a keymap with a prompt string is
  355. to specify the string as an argument when you call `make-keymap' or
  356. `make-sparse-keymap' (*note Creating Keymaps::.).
  357.  
  358.    The individual bindings in the menu keymap should also have prompt
  359. strings; these strings become the items displayed in the menu.  A
  360. binding with a prompt string looks like this:
  361.  
  362.      (STRING . REAL-BINDING)
  363.  
  364.    As far as `define-key' and `lookup-key' are concerned, the string is
  365. part of the event's binding.  However, only REAL-BINDING is used for
  366. executing the key.
  367.  
  368.    You can also supply a second string, called the help string, as
  369. follows:
  370.  
  371.      (STRING HELP-STRING . REAL-BINDING)
  372.  
  373.    Currently Emacs does not actually use HELP-STRING; it knows only how
  374. to ignore HELP-STRING in order to extract REAL-BINDING.  In the future
  375. we hope to make HELP-STRING serve as extended documentation for the
  376. menu item, available on request.
  377.  
  378.    The prompt string for a binding should be short--one or two words.
  379. It should describe the action of the command it corresponds to.
  380.  
  381.    If REAL-BINDING is `nil', then STRING appears in the menu but cannot
  382. be selected.
  383.  
  384.    If REAL-BINDING is a symbol, and has a non-`nil' `menu-enable'
  385. property, that property is an expression which controls whether the
  386. menu item is enabled.  Every time the keymap is used to display a menu,
  387. Emacs evaluates the expression, and it enables the menu item only if
  388. the expression's value is non-`nil'.  When a menu item is disabled, it
  389. is displayed in a "fuzzy" fashion, and cannot be selected with the
  390. mouse.
  391.  
  392.    The order of items in the menu is the same as the order of bindings
  393. in the keymap.  Since `define-key' puts new bindings at the front, you
  394. should define the menu items starting at the bottom of the menu and
  395. moving to the top, if you care about the order.
  396.  
  397. 
  398. File: elisp,  Node: Mouse Menus,  Next: Keyboard Menus,  Prev: Defining Menus,  Up: Menu Keymaps
  399.  
  400. Menus and the Mouse
  401. -------------------
  402.  
  403.    The way to make a menu keymap produce a menu is to make it the
  404. definition of a prefix key.
  405.  
  406.    When the prefix key ends with a mouse event, Emacs handles the menu
  407. keymap by popping up a visible menu, so that the user can select a
  408. choice with the mouse.  When the user clicks on a menu item, the event
  409. generated is whatever character or symbol has the binding which brought
  410. about that menu item.
  411.  
  412.    It's often best to use a button-down event to trigger the menu.  Then
  413. the user can select a menu item by releasing the button.
  414.  
  415.    A single keymap can appear as multiple menu panes, if you explicitly
  416. arrange for this.  The way to do this is to make a keymap for each pane,
  417. then create a binding for each of those maps in the main keymap of the
  418. menu.  Give each of these bindings a prompt string that starts with
  419. `@'.  The rest of the prompt string becomes the name of the pane.  See
  420. the file `lisp/mouse.el' for an example of this.  Any ordinary bindings
  421. with `@'-less prompt strings are grouped into one pane, which appears
  422. along with the other panes explicitly created for the submaps.
  423.  
  424.    You can also get multiple panes from separate keymaps.  The full
  425. definition of a prefix key always comes from merging the definitions
  426. supplied by the various active keymaps (minor mode, local, and global).
  427. When more than one of these keymaps is a menu, each of them makes a
  428. separate pane or panes.  *Note Active Keymaps::.
  429.  
  430.    A Lisp program can explicitly pop up a menu and receive the user's
  431. choice.  You can use keymaps for this also.  *Note Pop-Up Menus::.
  432.  
  433. 
  434. File: elisp,  Node: Keyboard Menus,  Next: Menu Example,  Prev: Mouse Menus,  Up: Menu Keymaps
  435.  
  436. Menus and the Keyboard
  437. ----------------------
  438.  
  439.    When a prefix key ending with a keyboard event (a character or
  440. function key) has a definition that is a menu keymap, the user can use
  441. the keyboard to choose a menu item.
  442.  
  443.    Emacs displays the menu alternatives (the prompt strings of the
  444. bindings) in the echo area.  If they don't all fit at once, the user can
  445. type SPC to see the next line of alternatives.  Successive uses of SPC
  446. eventually get to the end of the menu and then cycle around to the
  447. beginning.
  448.  
  449.    When the user has found the desired alternative from the menu, he or
  450. she should type the corresponding character--the one whose binding is
  451. that alternative.
  452.  
  453.    In a menu intended for keyboard use, each menu item must clearly
  454. indicate what character to type.  The best convention to use is to make
  455. the character the first letter of the menu item prompt string.  That is
  456. something users will understand without being told.
  457.  
  458.    This way of using menus in an Emacs-like editor was inspired by the
  459. Hierarkey system.
  460.  
  461.  - Variable: menu-prompt-more-char
  462.      This variable specifies the character to use to ask to see the
  463.      next line of a menu.  Its initial value is 32, the code for SPC.
  464.  
  465. 
  466. File: elisp,  Node: Menu Example,  Next: Menu Bar,  Prev: Keyboard Menus,  Up: Menu Keymaps
  467.  
  468. Menu Example
  469. ------------
  470.  
  471.    Here is a simple example of how to set up a menu for mouse use.
  472.  
  473.      (defvar my-menu-map
  474.        (make-sparse-keymap "Key Commands <==> Functions"))
  475.      (fset 'help-for-keys my-menu-map)
  476.      
  477.      (define-key my-menu-map [bindings]
  478.        '("List all keystroke commands" . describe-bindings))
  479.      (define-key my-menu-map [key]
  480.        '("Describe key briefly" . describe-key-briefly))
  481.      (define-key my-menu-map [key-verbose]
  482.        '("Describe key verbose" . describe-key))
  483.      (define-key my-menu-map [function]
  484.        '("Describe Lisp function" . describe-function))
  485.      (define-key my-menu-map [where-is]
  486.        '("Where is this command" . where-is))
  487.      
  488.      (define-key global-map [C-S-down-mouse-1] 'help-for-keys)
  489.  
  490.    The symbols used in the key sequences bound in the menu are
  491. fictitious "function keys"; they don't appear on the keyboard, but that
  492. doesn't stop you from using them in the menu.  Their names were chosen
  493. to be mnemonic, because they show up in the output of `where-is' and
  494. `apropos' to identify the corresponding menu items.
  495.  
  496.    However, if you want the menu to be usable from the keyboard as well,
  497. you must use real ASCII characters instead of fictitious function keys.
  498.  
  499. 
  500. File: elisp,  Node: Menu Bar,  Next: Modifying Menus,  Prev: Menu Example,  Up: Menu Keymaps
  501.  
  502. The Menu Bar
  503. ------------
  504.  
  505.    Under X Windows, each frame can have a "menu bar"--a permanently
  506. displayed menu stretching horizontally across the top of the frame.  The
  507. items of the menu bar are the subcommands of the fake "function key"
  508. `menu-bar', as defined by all the active keymaps.
  509.  
  510.    To add an item to the menu bar, invent a fake "function key" of your
  511. own (let's call it KEY), and make a binding for the key sequence
  512. `[menu-bar KEY]'.  Most often, the binding is a menu keymap, so that
  513. pressing a button on the menu bar item leads to another menu.
  514.  
  515.    When more than one active keymap defines the same fake function key
  516. for the menu bar, the item appears just once.  If the user clicks on
  517. that menu bar item, it brings up a single, combined submenu containing
  518. all the subcommands of that item--the global subcommands, the local
  519. subcommands, and the minor mode subcommands, all together.
  520.  
  521.    In order for a frame to display a menu bar, its `menu-bar-lines'
  522. property must be greater than zero.  Emacs uses just one line for the
  523. menu bar itself; if you specify more than one line, the other lines
  524. serve to separate the menu bar from the windows in the frame.  We
  525. recommend you try one or two as the value of `menu-bar-lines'.  *Note X
  526. Frame Parameters::.
  527.  
  528.    Here's an example of setting up a menu bar item:
  529.  
  530.      (modify-frame-parameters (selected-frame) '((menu-bar-lines . 2)))
  531.      
  532.      ;; Make a menu keymap (with a prompt string)
  533.      ;; to be the menu bar item's definition.
  534.      (define-key global-map [menu-bar words]
  535.        (cons "Words" (make-sparse-keymap "Words")))
  536.      
  537.      ;; Make specific subcommands in the item's submenu.
  538.      (define-key global-map
  539.        [menu-bar words forward]
  540.        '("Forward word" . forward-word))
  541.      (define-key global-map
  542.        [menu-bar words backward]
  543.        '("Backward word" . backward-word))
  544.  
  545.    A local keymap can cancel a menu bar item made by the global keymap
  546. by rebinding the same fake function key with `undefined' as the
  547. binding.  For example, this is how Dired suppresses the `Edit' menu bar
  548. item:
  549.  
  550.      (define-key dired-mode-map [menu-bar edit] 'undefined)
  551.  
  552. `edit' is the fake function key used by the global map for the `Edit'
  553. menu bar item.  The main reason to suppress a global menu bar item is
  554. to regain space for mode-specific items.
  555.  
  556.  - Variable: menu-bar-final-items
  557.      Normally the menu bar shows global items followed by items defined
  558.      by the local maps.
  559.  
  560.      This variable holds a list of fake function keys for items to
  561.      display at the end of the menu bar rather than in normal sequence.
  562.      The default value is `(help)'; thus, the `Help' menu item
  563.      normally appears at the end of the menu bar, following local menu
  564.      items.
  565.  
  566. 
  567. File: elisp,  Node: Modifying Menus,  Prev: Menu Bar,  Up: Menu Keymaps
  568.  
  569. Modifying Menus
  570. ---------------
  571.  
  572.    When you insert a new item in an existing menu, you probably want to
  573. put it in a particular place among the menu's existing items.  If you
  574. use `define-key' to add the item, it normally goes at the front of the
  575. menu.  To put it elsewhere, use `define-key-after':
  576.  
  577.  - Function: define-key-after MAP KEY BINDING AFTER
  578.      Define a binding in MAP for KEY, with value BINDING, just like
  579.      `define-key', but position the binding in MAP after the binding
  580.      for the key AFTER.  For example,
  581.  
  582.           (define-key my-menu [drink]
  583.                       '("Drink" . drink-command) [eat])
  584.  
  585.      makes a binding for the fake function key drink and puts it right
  586.      after the binding for eat.
  587.  
  588. 
  589. File: elisp,  Node: Active Keymaps,  Next: Key Lookup,  Prev: Menu Keymaps,  Up: Keymaps
  590.  
  591. Active Keymaps
  592. ==============
  593.  
  594.    Emacs normally contains many keymaps; at any given time, just a few
  595. of them are "active" in that they participate in the interpretation of
  596. user input.  These are the global keymap, the current buffer's local
  597. keymap, and the keymaps of any enabled minor modes.
  598.  
  599.    The "global keymap" holds the bindings of keys that are defined
  600. regardless of the current buffer, such as `C-f'.  The variable
  601. `global-map' holds this keymap, which is always active.
  602.  
  603.    Each buffer may have another keymap, its "local keymap", which may
  604. contain new or overriding definitions for keys.  At all times, the
  605. current buffer's local keymap is active.  Text properties can specify an
  606. alternative local map for certain parts of the buffer; see *Note
  607. Special Properties::.
  608.  
  609.    Each minor mode may have a keymap; if it does, the keymap is active
  610. whenever the minor mode is enabled.
  611.  
  612.    All the active keymaps are used together to determine what command to
  613. execute when a key is entered.  The key lookup proceeds as described
  614. earlier (*note Key Lookup::.), but Emacs *first* searches for the key
  615. in the minor mode maps (one map at a time); if they do not supply a
  616. binding for the key, Emacs searches the local map; if that too has no
  617. binding, Emacs then searches the global map.
  618.  
  619.    Since every buffer that uses the same major mode normally uses the
  620. very same local keymap, it may appear as if the keymap is local to the
  621. mode.  A change to the local keymap of a buffer (using `local-set-key',
  622. for example) will be seen also in the other buffers that share that
  623. keymap.
  624.  
  625.    The local keymaps that are used for Lisp mode, C mode, and several
  626. other major modes exist even if they have not yet been used.  These
  627. local maps are the values of the variables `lisp-mode-map',
  628. `c-mode-map', and so on.  For most other modes, which are less
  629. frequently used, the local keymap is constructed only when the mode is
  630. used for the first time in a session.
  631.  
  632.    The minibuffer has local keymaps, too; they contain various
  633. completion and exit commands.  *Note Minibuffers::.
  634.  
  635.    *Note Standard Keymaps::, for a list of standard keymaps.
  636.  
  637.  - Variable: global-map
  638.      This variable contains the default global keymap that maps Emacs
  639.      keyboard input to commands.  Normally this keymap is the global
  640.      keymap.  The default global keymap is a full keymap that binds
  641.      `self-insert-command' to all of the printing characters.
  642.  
  643.  - Function: current-global-map
  644.      This function returns the current global keymap.  This is always
  645.      the same as the value of `global-map' unless you change one or the
  646.      other.
  647.  
  648.           (current-global-map)
  649.           => (keymap [set-mark-command beginning-of-line ...
  650.                       delete-backward-char])
  651.  
  652.  - Function: current-local-map
  653.      This function returns the current buffer's local keymap, or `nil'
  654.      if it has none.  In the following example, the keymap for the
  655.      `*scratch*' buffer (using Lisp Interaction mode) is a sparse keymap
  656.      in which the entry for ESC, ASCII code 27, is another sparse
  657.      keymap.
  658.  
  659.           (current-local-map)
  660.           => (keymap
  661.               (10 . eval-print-last-sexp)
  662.               (9 . lisp-indent-line)
  663.               (127 . backward-delete-char-untabify)
  664.               (27 keymap
  665.                   (24 . eval-defun)
  666.                   (17 . indent-sexp)))
  667.  
  668.  - Function: current-minor-mode-maps
  669.      This function returns a list of the keymaps of currently enabled
  670.      minor modes.
  671.  
  672.  - Function: use-global-map KEYMAP
  673.      This function makes KEYMAP the new current global keymap.  It
  674.      returns `nil'.
  675.  
  676.      It is very unusual to change the global keymap.
  677.  
  678.  - Function: use-local-map KEYMAP
  679.      This function makes KEYMAP the new current local keymap of the
  680.      current buffer.  If KEYMAP is `nil', then there will be no local
  681.      keymap.  It returns `nil'.  Most major modes use this function.
  682.  
  683.  - Variable: minor-mode-map-alist
  684.      This variable is an alist describing keymaps that may or may not be
  685.      active according to the values of certain variables.  Its elements
  686.      look like this:
  687.  
  688.           (VARIABLE . KEYMAP)
  689.  
  690.      The keymap KEYMAP is active whenever VARIABLE has a non-`nil'
  691.      value.  Typically VARIABLE is the variable which enables or
  692.      disables a minor mode.  *Note Keymaps and Minor Modes::.
  693.  
  694.      When more than one minor mode keymap is active, their order of
  695.      priority is the order of `minor-mode-map-alist'.
  696.  
  697.      See also `minor-mode-key-binding' in *Note Functions for Key
  698.      Lookup::.
  699.  
  700. 
  701. File: elisp,  Node: Key Lookup,  Next: Functions for Key Lookup,  Prev: Active Keymaps,  Up: Keymaps
  702.  
  703. Key Lookup
  704. ==========
  705.  
  706.    "Key lookup" is the process of finding the binding of a key sequence
  707. from a given keymap.  Actual execution of the binding is not part of
  708. key lookup.
  709.  
  710.    Key lookup uses just the event types of each event in the key
  711. sequence; the rest of the event is ignored.  In fact, a key sequence
  712. used for key lookup may designate mouse events with just their types
  713. (symbols) instead of with entire mouse events (lists).  *Note Input
  714. Events::.  Such a pseudo-key-sequence is insufficient for
  715. `command-execute', but it is sufficient for looking up or rebinding a
  716. key.
  717.  
  718.    When the key sequence consists of multiple events, key lookup
  719. processes the events sequentially: the binding of the first event is
  720. found, and must be a keymap; then the second event's binding is found in
  721. that keymap, and so on until all the events in the key sequence are used
  722. up.  (The binding thus found for the last event may or may not be a
  723. keymap.)  Thus, the process of key lookup is defined in terms of a
  724. simpler process for looking up a single event in a keymap.  How that is
  725. done depends on the type of object associated with the event in that
  726. keymap.
  727.  
  728.    Let's use the term "keymap entry" to describe the value directly
  729. associated with an event type in a keymap.  While any Lisp object may be
  730. stored as a keymap entry, not all make sense for key lookup.  Here is a
  731. list of the meaningful kinds of keymap entries:
  732.  
  733. `nil'
  734.      `nil' means that the events used so far in the lookup form an
  735.      undefined key.  When a keymap fails to mention an event type at
  736.      all, that is equivalent to an entry of `nil' for that type.
  737.  
  738. KEYMAP
  739.      The events used so far in the lookup form a prefix key.  The next
  740.      event of the key sequence is looked up in KEYMAP.
  741.  
  742. COMMAND
  743.      The events used so far in the lookup form a complete key, and
  744.      COMMAND is its binding.
  745.  
  746. STRING
  747. VECTOR
  748.      The events used so far in the lookup form a complete key, whose
  749.      binding is a keyboard macro.  See *Note Keyboard Macros::, for more
  750.      information.
  751.  
  752. LIST
  753.      The meaning of a list depends on the types of the elements of the
  754.      list.
  755.  
  756.         * If the CAR of LIST is the symbol `keymap', then the list is a
  757.           keymap, and is treated as a keymap (see above).
  758.  
  759.         * If the CAR of LIST is `lambda', then the list is a lambda
  760.           expression.  This is presumed to be a command, and is treated
  761.           as such (see above).
  762.  
  763.         * If the CAR of LIST is a keymap and the CDR is an event type,
  764.           then this is an "indirect entry":
  765.  
  766.                (OTHERMAP . OTHERTYPE)
  767.  
  768.           When key lookup encounters an indirect entry, it looks up
  769.           instead the binding of OTHERTYPE in OTHERMAP and uses that.
  770.  
  771.           This feature permits you to define one key as an alias for
  772.           another key.  For example, an entry whose CAR is the keymap
  773.           called `esc-map' and whose CDR is 32 (the code for space)
  774.           means, "Use the global binding of `Meta-SPC', whatever that
  775.           may be."
  776.  
  777.         * If the CAR of LIST is a string, it serves as a menu item name
  778.           if the keymap is used as a menu.  For executing the key, the
  779.           string is discarded and the CDR of LIST is used instead.
  780.           (Any number of strings can be discarded from the front of the
  781.           list in this way.) *Note Menu Keymaps::.
  782.  
  783. SYMBOL
  784.      The function definition of SYMBOL is used in place of SYMBOL.  If
  785.      that too is a symbol, then this process is repeated, any number of
  786.      times.  Ultimately this should lead to an object which is a
  787.      keymap, a command or a keyboard macro.  A list is allowed if it is
  788.      a keymap or a command, but indirect entries are not understood
  789.      when found via symbols.
  790.  
  791.      Note that keymaps and keyboard macros (strings and vectors) are not
  792.      valid functions, so a symbol with a keymap, string or vector as its
  793.      function definition is also invalid as a function.  It is, however,
  794.      valid as a key binding.  If the definition is a keyboard macro,
  795.      then the symbol is also valid as an argument to `command-execute'
  796.      (*note Interactive Call::.).
  797.  
  798.      The symbol `undefined' is worth special mention: it means to treat
  799.      the key as undefined.  Strictly speaking, the key is defined, and
  800.      its binding is the command `undefined'; but that command does the
  801.      same thing that is done automatically for an undefined key: it
  802.      rings the bell (by calling `ding') but does not signal an error.
  803.  
  804.      `undefined' is used in local keymaps to override a global key
  805.      binding and make the key "undefined" locally.  A local binding of
  806.      `nil' would fail to do this because it would not override the
  807.      global binding.
  808.  
  809. ANYTHING ELSE
  810.      If any other type of object is found, the events used so far in the
  811.      lookup form a complete key, and the object is its binding, but the
  812.      binding is not executable as a command.
  813.  
  814.    In short, a keymap entry may be a keymap, a command, a keyboard
  815. macro, a symbol which leads to one of them, or an indirection or `nil'.
  816. Here is an example of a sparse keymap with two characters bound to
  817. commands and one bound to another keymap.  This map is the normal value
  818. of `emacs-lisp-mode-map'.  Note that 9 is the code for TAB, 127 for
  819. DEL, 27 for ESC, 17 for `C-q' and 24 for `C-x'.
  820.  
  821.      (keymap (9 . lisp-indent-line)
  822.              (127 . backward-delete-char-untabify)
  823.              (27 keymap (17 . indent-sexp) (24 . eval-defun)))
  824.  
  825. 
  826. File: elisp,  Node: Functions for Key Lookup,  Next: Changing Key Bindings,  Prev: Key Lookup,  Up: Keymaps
  827.  
  828. Functions for Key Lookup
  829. ========================
  830.  
  831.    Here are the functions and variables pertaining to key lookup.
  832.  
  833.  - Function: lookup-key KEYMAP KEY &optional ACCEPT-DEFAULTS
  834.      This function returns the definition of KEY in KEYMAP.  If the
  835.      string or vector KEY is not a valid key sequence according to the
  836.      prefix keys specified in KEYMAP (which means it is "too long" and
  837.      has extra events at the end), then the value is a number, the
  838.      number of events at the front of KEY that compose a complete key.
  839.  
  840.      If ACCEPT-DEFAULTS is non-`nil', then `lookup-key' considers
  841.      default bindings as well as bindings for the specific events in
  842.      KEY.  Otherwise, `lookup-key' reports only bindings for the
  843.      specific sequence KEY, ignoring default bindings except when an
  844.      element of KEY is `t'.
  845.  
  846.      All the other functions described in this chapter that look up
  847.      keys use `lookup-key'.
  848.  
  849.           (lookup-key (current-global-map) "\C-x\C-f")
  850.               => find-file
  851.           (lookup-key (current-global-map) "\C-x\C-f12345")
  852.               => 2
  853.  
  854.      If KEY contains a meta character, that character is implicitly
  855.      replaced by a two-character sequence: the value of
  856.      `meta-prefix-char', followed by the corresponding non-meta
  857.      character.  Thus, the first example below is handled by conversion
  858.      into the second example.
  859.  
  860.           (lookup-key (current-global-map) "\M-f")
  861.               => forward-word
  862.           (lookup-key (current-global-map) "\ef")
  863.               => forward-word
  864.  
  865.      This function does not modify the specified events in ways that
  866.      discard information as `read-key-sequence' does (*note Key
  867.      Sequence Input::.).  In particular, it does not convert letters to
  868.      lower case and it does not change drag events to clicks.
  869.  
  870.  - Command: undefined
  871.      Used in keymaps to undefine keys.  It calls `ding', but does not
  872.      cause an error.
  873.  
  874.  - Function: key-binding KEY &optional ACCEPT-DEFAULTS
  875.      This function returns the binding for KEY in the current keymaps,
  876.      trying all the active keymaps.  The result is `nil' if KEY is
  877.      undefined in the keymaps.
  878.  
  879.      The argument ACCEPT-DEFAULTS controls checking for default
  880.      bindings, as in `lookup-key'.
  881.  
  882.      An error is signaled if KEY is not a string or a vector.
  883.  
  884.           (key-binding "\C-x\C-f")
  885.               => find-file
  886.  
  887.  - Function: local-key-binding KEY &optional ACCEPT-DEFAULTS
  888.      This function returns the binding for KEY in the current local
  889.      keymap, or `nil' if it is undefined there.
  890.  
  891.      The argument ACCEPT-DEFAULTS controls checking for default
  892.      bindings, as in `lookup-key' (above).
  893.  
  894.  - Function: global-key-binding KEY &optional ACCEPT-DEFAULTS
  895.      This function returns the binding for command KEY in the current
  896.      global keymap, or `nil' if it is undefined there.
  897.  
  898.      The argument ACCEPT-DEFAULTS controls checking for default
  899.      bindings, as in `lookup-key' (above).
  900.  
  901.  - Function: minor-mode-key-binding KEY &optional ACCEPT-DEFAULTS
  902.      This function returns a list of all the active minor mode bindings
  903.      of KEY.  More precisely, it returns an alist of pairs `(MODENAME .
  904.      BINDING)', where MODENAME is the the variable which enables the
  905.      minor mode, and BINDING is KEY's binding in that mode.  If KEY has
  906.      no minor-mode bindings, the value is `nil'.
  907.  
  908.      If the first binding is a non-prefix, all subsequent bindings from
  909.      other minor modes are omitted, since they would be completely
  910.      shadowed.  Similarly, the list omits non-prefix bindings that
  911.      follow prefix bindings.
  912.  
  913.      The argument ACCEPT-DEFAULTS controls checking for default
  914.      bindings, as in `lookup-key' (above).
  915.  
  916.  - Variable: meta-prefix-char
  917.      This variable is the meta-prefix character code.  It is used when
  918.      translating a meta character to a two-character sequence so it can
  919.      be looked up in a keymap.  For useful results, the value should be
  920.      a prefix event (*note Prefix Keys::.).  The default value is 27,
  921.      which is the ASCII code for ESC.
  922.  
  923.      As long as the value of `meta-prefix-char' remains 27, key lookup
  924.      translates `M-b' into `ESC b', which is normally defined as the
  925.      `backward-word' command.  However, if you set `meta-prefix-char'
  926.      to 24, the code for `C-x', then Emacs will translate `M-b' into
  927.      `C-x b', whose standard binding is the `switch-to-buffer' command.
  928.  
  929.           meta-prefix-char                    ; The default value.
  930.                => 27
  931.  
  932.           (key-binding "\M-b")
  933.                => backward-word
  934.  
  935.           ?\C-x                               ; The print representation
  936.                => 24                          ;   of a character.
  937.  
  938.           (setq meta-prefix-char 24)
  939.                => 24
  940.  
  941.           (key-binding "\M-b")
  942.                => switch-to-buffer            ; Now, typing `M-b' is
  943.                                               ;   like typing `C-x b'.
  944.           
  945.           (setq meta-prefix-char 27)          ; Avoid confusion!
  946.                => 27                          ; Restore the default value!
  947.  
  948. 
  949. File: elisp,  Node: Changing Key Bindings,  Next: Key Binding Commands,  Prev: Functions for Key Lookup,  Up: Keymaps
  950.  
  951. Changing Key Bindings
  952. =====================
  953.  
  954.    The way to rebind a key is to change its entry in a keymap.  You can
  955. change the global keymap, so that the change is effective in all buffers
  956. (except those that override the global binding with a local one).  Or
  957. you can change the current buffer's local map, which usually affects all
  958. buffers using the same major mode.  The `global-set-key' and
  959. `local-set-key' functions are convenient interfaces for these
  960. operations.  Or you can use `define-key' and specify explicitly which
  961. map to change.
  962.  
  963.    People often use `global-set-key' in their `.emacs' file for simple
  964. customization.  For example,
  965.  
  966.      (global-set-key "\C-x\C-\\" 'next-line)
  967.  
  968. or
  969.  
  970.      (global-set-key [?\C-x ?\C-\\] 'next-line)
  971.  
  972. redefines `C-x C-\' to move down a line.
  973.  
  974.      (global-set-key [M-mouse-1] 'mouse-set-point)
  975.  
  976. redefines the first (leftmost) mouse button, typed with the Meta key, to
  977. set point where you click.
  978.  
  979.    In writing the key sequence to rebind, it is useful to use the
  980. special escape sequences for control and meta characters (*note String
  981. Type::.).  The syntax `\C-' means that the following character is a
  982. control character and `\M-' means that the following character is a meta
  983. character.  Thus, the string `"\M-x"' is read as containing a single
  984. `M-x', `"\C-f"' is read as containing a single `C-f', and `"\M-\C-x"'
  985. and `"\C-\M-x"' are both read as containing a single `C-M-x'.
  986.  
  987.    For the functions below, an error is signaled if KEYMAP is not a
  988. keymap or if KEY is not a string or vector representing a key sequence.
  989. However, you can use event types (symbols) as shorthand for events
  990. that are lists.
  991.  
  992.  - Function: define-key KEYMAP KEY BINDING
  993.      This function sets the binding for KEY in KEYMAP.  (If KEY is more
  994.      than one event long, the change is actually made in another keymap
  995.      reached from KEYMAP.)  The argument BINDING can be any Lisp
  996.      object, but only certain types are meaningful.  (For a list of
  997.      meaningful types, see *Note Key Lookup::.) The value returned by
  998.      `define-key' is BINDING.
  999.  
  1000.      Every prefix of KEY must be a prefix key (i.e., bound to a keymap)
  1001.      or undefined; otherwise an error is signaled.
  1002.  
  1003.      If some prefix of KEY is undefined, then `define-key' defines it
  1004.      as a prefix key so that the rest of KEY may be defined as
  1005.      specified.
  1006.  
  1007.      The following example creates a sparse keymap and makes a number of
  1008.      bindings:
  1009.  
  1010.           (setq map (make-sparse-keymap))
  1011.               => (keymap)
  1012.  
  1013.           (define-key map "\C-f" 'forward-char)
  1014.               => forward-char
  1015.  
  1016.           map
  1017.               => (keymap (6 . forward-char))
  1018.  
  1019.           ;; Build sparse submap for `C-x' and bind `f' in that.
  1020.           (define-key map "\C-xf" 'forward-word)
  1021.               => forward-word
  1022.  
  1023.           map
  1024.           => (keymap
  1025.               (24 keymap                ; `C-x'
  1026.                   (102 . forward-word)) ;      `f'
  1027.               (6 . forward-char))       ; `C-f'
  1028.  
  1029.           ;; Bind `C-p' to the `ctl-x-map'.
  1030.           (define-key map "\C-p" ctl-x-map)
  1031.           ;; `ctl-x-map'
  1032.           => [nil ... find-file ... backward-kill-sentence]
  1033.  
  1034.           ;; Bind `C-f' to `foo' in the `ctl-x-map'.
  1035.           (define-key map "\C-p\C-f" 'foo)
  1036.           => 'foo
  1037.  
  1038.           map
  1039.           => (keymap     ; Note `foo' in `ctl-x-map'.
  1040.               (16 keymap [nil ... foo ... backward-kill-sentence])
  1041.               (24 keymap
  1042.                   (102 . forward-word))
  1043.               (6 . forward-char))
  1044.  
  1045.      Note that storing a new binding for `C-p C-f' actually works by
  1046.      changing an entry in `ctl-x-map', and this has the effect of
  1047.      changing the bindings of both `C-p C-f' and `C-x C-f' in the
  1048.      default global map.
  1049.  
  1050.  - Function: substitute-key-definition OLDDEF NEWDEF KEYMAP &optional
  1051.           OLDMAP
  1052.      This function replaces OLDDEF with NEWDEF for any keys in KEYMAP
  1053.      that were bound to OLDDEF.  In other words, OLDDEF is replaced
  1054.      with NEWDEF wherever it appears.  The function returns `nil'.
  1055.  
  1056.      For example, this redefines `C-x C-f', if you do it in an Emacs
  1057.      with standard bindings:
  1058.  
  1059.           (substitute-key-definition
  1060.            'find-file 'find-file-read-only (current-global-map))
  1061.  
  1062.      If OLDMAP is non-`nil', then its bindings determine which keys to
  1063.      rebind.  The rebindings still happen in NEWMAP, not in OLDMAP.
  1064.      Thus, you can change one map under the control of the bindings in
  1065.      another.  For example,
  1066.  
  1067.           (substitute-key-definition
  1068.             'delete-backward-char 'my-funny-delete
  1069.             my-map global-map)
  1070.  
  1071.      puts the special deletion command in `my-map' for whichever keys
  1072.      are globally bound to the standard deletion command.
  1073.  
  1074.      Here is an example showing a keymap before and after substitution:
  1075.  
  1076.           (setq map '(keymap
  1077.                       (?1 . olddef-1)
  1078.                       (?2 . olddef-2)
  1079.                       (?3 . olddef-1)))
  1080.           => (keymap (49 . olddef-1) (50 . olddef-2) (51 . olddef-1))
  1081.  
  1082.           (substitute-key-definition 'olddef-1 'newdef map)
  1083.           => nil
  1084.  
  1085.           map
  1086.           => (keymap (49 . newdef) (50 . olddef-2) (51 . newdef))
  1087.  
  1088.  - Function: suppress-keymap KEYMAP &optional NODIGITS
  1089.      This function changes the contents of the full keymap KEYMAP by
  1090.      replacing the self-insertion commands for numbers with the
  1091.      `digit-argument' function, unless NODIGITS is non-`nil', and by
  1092.      replacing the functions for the rest of the printing characters
  1093.      with `undefined'.  This means that ordinary insertion of text is
  1094.      impossible in a buffer with a local keymap on which
  1095.      `suppress-keymap' has been called.
  1096.  
  1097.      `suppress-keymap' returns `nil'.
  1098.  
  1099.      The `suppress-keymap' function does not make it impossible to
  1100.      modify a buffer, as it does not suppress commands such as `yank'
  1101.      and `quoted-insert'.  To prevent any modification of a buffer, make
  1102.      it read-only (*note Read Only Buffers::.).
  1103.  
  1104.      Since this function modifies KEYMAP, you would normally use it on
  1105.      a newly created keymap.  Operating on an existing keymap that is
  1106.      used for some other purpose is likely to cause trouble; for
  1107.      example, suppressing `global-map' would make it impossible to use
  1108.      most of Emacs.
  1109.  
  1110.      Most often, `suppress-keymap' is used to initialize local keymaps
  1111.      of modes such as Rmail and Dired where insertion of text is not
  1112.      desirable and the buffer is read-only.  Here is an example taken
  1113.      from the file `emacs/lisp/dired.el', showing how the local keymap
  1114.      for Dired mode is set up:
  1115.  
  1116.           ...
  1117.             (setq dired-mode-map (make-keymap))
  1118.             (suppress-keymap dired-mode-map)
  1119.             (define-key dired-mode-map "r" 'dired-rename-file)
  1120.             (define-key dired-mode-map "\C-d" 'dired-flag-file-deleted)
  1121.             (define-key dired-mode-map "d" 'dired-flag-file-deleted)
  1122.             (define-key dired-mode-map "v" 'dired-view-file)
  1123.             (define-key dired-mode-map "e" 'dired-find-file)
  1124.             (define-key dired-mode-map "f" 'dired-find-file)
  1125.             ...
  1126.  
  1127. 
  1128. File: elisp,  Node: Key Binding Commands,  Next: Scanning Keymaps,  Prev: Changing Key Bindings,  Up: Keymaps
  1129.  
  1130. Commands for Binding Keys
  1131. =========================
  1132.  
  1133.    This section describes some convenient interactive interfaces for
  1134. changing key bindings.  They work by calling `define-key'.
  1135.  
  1136.  - Command: global-set-key KEY DEFINITION
  1137.      This function sets the binding of KEY in the current global map to
  1138.      DEFINITION.
  1139.  
  1140.           (global-set-key KEY DEFINITION)
  1141.           ==
  1142.           (define-key (current-global-map) KEY DEFINITION)
  1143.  
  1144.  - Command: global-unset-key KEY
  1145.      This function removes the binding of KEY from the current global
  1146.      map.
  1147.  
  1148.      One use of this function is in preparation for defining a longer
  1149.      key which uses it implicitly as a prefix--which would not be
  1150.      allowed if KEY has a non-prefix binding.  For example:
  1151.  
  1152.           (global-unset-key "\C-l")
  1153.               => nil
  1154.  
  1155.           (global-set-key "\C-l\C-l" 'redraw-display)
  1156.               => nil
  1157.  
  1158.      This function is implemented simply using `define-key':
  1159.  
  1160.           (global-unset-key KEY)
  1161.           ==
  1162.           (define-key (current-global-map) KEY nil)
  1163.  
  1164.  - Command: local-set-key KEY DEFINITION
  1165.      This function sets the binding of KEY in the current local keymap
  1166.      to DEFINITION.
  1167.  
  1168.           (local-set-key KEY DEFINITION)
  1169.           ==
  1170.           (define-key (current-local-map) KEY DEFINITION)
  1171.  
  1172.  - Command: local-unset-key KEY
  1173.      This function removes the binding of KEY from the current local
  1174.      map.
  1175.  
  1176.           (local-unset-key KEY)
  1177.           ==
  1178.           (define-key (current-local-map) KEY nil)
  1179.  
  1180.